#### Code to produce results reported in the main text  ####
#### Figure 4: Open-ended responses ####
## Author: Jeong Hyun Kim
## Last updated: 12/29/2021

library(foreign)
library(tidyverse)
library(broom)
library(stargazer)

df <- read.csv("survey_with_openended.csv")

df <- df %>% select(-BQ2.y)
df <- df %>% rename(BQ2 = BQ2.x)

df$young1 <- ifelse(df$BQ3 < 40, 1, 0)
df <- df %>% mutate(gender  = ifelse(BQ2=="1", "Men", "Women"),
                    gender= factor(gender, levels=c("Men", "Women")))

df.men <- df %>% filter(BQ2=="1")
df.women <- df %>% filter(BQ2 == 2)
df.men.y <- df.men %>% filter(young1==1)
df.women.y <- df.women %>% filter(young1==1)  

#### Figure 4 Panel (a) Male Respondents ####
p2 <- ggplot(df.men, aes(as.factor(treated), men_decrease, fill= reorder(young1, desc(young1)))) +
  stat_summary(fun = mean, geom="bar", width=.75, position = position_dodge()) +
  stat_summary(fun.data = mean_cl_normal, geom= "errorbar",  width=0.1, alpha=1, size = 1,position = position_dodge(width = 0.75)) +
  theme_bw() + scale_fill_manual(values = c("1" = "grey85", "0" = "grey55"),
                                 labels = c("Young Men (<40)", "Old Men (>=40)"),
                                 name = c(""))  +
  scale_y_continuous(labels=function(x) x*100) +
  theme(legend.text = element_text(size = 18),
        legend.position = "bottom",
        axis.text.y = element_text(size = 18),
        axis.text.x = element_text(size = 18),  axis.title.y = element_text(size = 18))  + xlab("") + ylab("% Respondents answered \n quota will decrease men's status")  + scale_x_discrete(limits=c("0", "1"), labels=c("Control", "Treatment")) + ggtitle("") + theme(text = element_text(size=12))  + coord_cartesian(ylim=c(0, 0.6))
p2

#### Figure 4 Panel (b) Female Respondents
p3 <- ggplot(df.women, aes(as.factor(treated), men_decrease, fill= reorder(young1, desc(young1)))) +
  stat_summary(fun = mean, geom="bar", width=.75, position = position_dodge()) +
  stat_summary(fun.data = mean_cl_normal, geom= "errorbar",  width=0.1, alpha=1, size = 1,position = position_dodge(width = 0.75)) +
  theme_bw() + scale_fill_manual(values = c("1" = "grey85", "0" = "grey55"),
                                 labels = c("Young Women (<40)", "Old Women (>=40)"),
                                 name = c(""))  +
  scale_y_continuous(labels=function(x) x*100) +
  theme(legend.text = element_text(size = 18),
        legend.position = "bottom",
        axis.text.y = element_text(size = 18),
        axis.text.x = element_text(size = 18),  axis.title.y = element_text(size = 18))  + xlab("") + ylab("% Respondents answered \n quota will decrease men's status")  + scale_x_discrete(limits=c("0", "1"), labels=c("Control", "Treatment")) + ggtitle("") + theme(text = element_text(size=12))  + coord_cartesian(ylim=c(0, 0.6))
p3
